package com.ctbu.sbdemol.service;

import com.ctbu.sbdemol.dao.AdminRepository;
import com.ctbu.sbdemol.entity.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.naming.Name;
import java.util.List;
import java.util.Optional;

/**
 * 管理员的服务对象
 */
@Service
public class AdminService {
    /**
     * 管理员的接口对象
     */

    @Autowired
    private AdminRepository adminRepository;

    /**
     * 返回所有的管理员
     * @return
     */
    public List<Admin>findAll(){
        return adminRepository.findAll();
    }

    /**
     * 返回所有查找的名字
     * @param Name
     * @return
     */
   public List<Admin> findByNameOld(String Name) {
        return  adminRepository.findAdminByName(Name);
    }

    /**
     * 新增一个admin
     * @param admin
     */
    public  void  Save(Admin admin)
    {
        adminRepository.save(admin);
    }


    /**
     * 根据id查找主键
     * @param
     * @return
     */
    public Optional<Admin> findById(Integer id)
    {
        Optional<Admin>myAdmin=adminRepository.findById(id);
        return  myAdmin;
    }
    /**
     * 根据名字查找
     * @param
     * @return
     */
    public  List<Admin>findByName(String Name){
        List<Admin>myAdmin=adminRepository.findAdminByName(Name);
        return  myAdmin;
    }


    /**
     * Admin 类，admin对象
     * @param admin
     */

    public  Admin save(Admin admin)
    {
        adminRepository.save(admin);
        return  admin;
    }

    public Admin update(Admin admin) {
        adminRepository.save(admin);
        return  admin;
    }
    public Admin delete(Admin admin)
    {
        adminRepository.delete(admin);
        return admin;
    }
}
